package com.example.test.启动线程.读锁与写锁;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Task implements Runnable {

    private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();


    private Lock readLock = readWriteLock.readLock();

    @Override
    public void run() {
        try {
            readLock.lock();
            try {
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        } finally {
            readLock.unlock();
        }

    }
}
